home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / aterminfo.lha / lib_trace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.2 KB  |  80 lines

  1.  
  2. /* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for   *
  3. *  details. If they are missing then this copy is in violation of    *
  4. *  the copyright conditions.                                        */
  5.  
  6. /*
  7.  *    lib_trace.c - Tracing/Debugging routines
  8.  */
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <fcntl.h>
  13. #ifndef AMIGA
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <errno.h>
  18. #include "term.h"
  19. #ifdef BRAINDEAD
  20. extern int errno;
  21. extern char *sys_errlist[];
  22. #endif
  23.  
  24. int _tracing =
  25. #ifdef TRACE
  26.     1
  27. #else
  28.     0
  29. #endif
  30. ;
  31.  
  32. static int    tracefd;
  33.  
  34. void _tracef(char *fmt, ...);
  35.  
  36. void _init_trace()
  37. {
  38. static int    been_here = 0;
  39.  
  40.     if (! been_here) {
  41.         been_here = 1;
  42.  
  43.             if ((tracefd = creat("trace", 0644)) < 0) {
  44.             write(2, "curses: Can't open 'trace' file: ", 33);
  45.             write(2, sys_errlist[errno], strlen(sys_errlist[errno]));
  46.             write(2, "\n", 1);
  47.             exit(1);
  48.             }
  49.     }
  50. }
  51.  
  52.  
  53. void traceon()
  54. {
  55.     _tracef("traceon() called");
  56.  
  57.         _tracing = 1;
  58. }
  59.  
  60.  
  61. void traceoff()
  62. {
  63.     _tracef("traceoff() called");
  64.  
  65.         _tracing = 0;
  66. }
  67.  
  68. void
  69. _tracef(char *fmt, ...)
  70. {
  71. va_list ap;
  72. char buffer[256];
  73.  
  74.     va_start(ap, fmt);
  75.     vsprintf(buffer, fmt, ap);
  76.     write(tracefd, buffer, strlen(buffer));
  77.     write(tracefd, "\n", 1);
  78. }
  79.  
  80.